import request from '@/utils/request'
// 申请公共主表 API接口
const apl_mainApi = {
  list: '/apl_main/list',
  save: '/apl_main/save',
  view: '/apl_main/view',
  del: '/apl_main/delete',
  dels: '/apl_main/batchDel',
  export: '/apl_main/export',
  exportExcelTemplate: '/apl_main/exportExcelTemplate',
  importExcel: '/apl_main/importExcel',
  saveApplyForm: '/apl_main/saveApplyForm',
  loadApplyForm: '/apl_main/loadApplyForm',
  formRemoveById: '/apl_main/formRemoveById',
  submitAccept: '/apl_main/accept',
  submitRefuse: '/apl_main/submitRefuse',
  viewAppend: '/apl_main/viewAppend',
  submitAppend: '/apl_main/submitAppend',
  submitBack: '/apl_main/submitBack',
  receiveStart: '/aprv_process_materials/receiveStart',
  checkAttachPass: '/apl_main/checkAttachPass',
  checkAttachAppend: '/apl_main/checkAttachAppend',
  queryBusineTree: '/apl_main/queryBusineTree',
  getByInstids: '/apl_main/getByid',
  queryTaskidByApplyid: '/apl_main/queryTaskidByApplyid',
  exportAllCase: '/apl_main/exportAllCase'
}

/**
 * 根据业务id查询流程taskid
 */
 export function queryTaskidByApplyid (applyid) {
  return request({
    url: apl_mainApi.queryTaskidByApplyid,
    method: 'post',
    params: {
      applyid
    }
  })
}

/**
 * 查询业务分派树
 */
 export function queryBusineTree (applyid, departid) {
  return request({
    url: apl_mainApi.queryBusineTree,
    method: 'post',
    params: {
      applyid, departid
    }
  })
}

/**
 * 查询是否存在待补正或补正待审查材料，判断审批通过（目前用于提示）
 * @param applyid
 * @return
 * @throws Exception
 */
export function checkAttachPass (applyid) {
  return request({
    url: apl_mainApi.checkAttachPass,
    method: 'post',
    params: {
      applyid
    }
  })
}

/**
 * 查询是否存在待补正材料，判断补正或退回（目前用于提示）
 * @param applyid
 * @return
 * @throws Exception
 */
export function checkAttachAppend (applyid) {
  return request({
    url: apl_mainApi.checkAttachAppend,
    method: 'post',
    params: {
      applyid
    }
  })
}

/**
 *  删除申请表字段记录
 * @param table 表名
 * @param primarykey 删除字段名
 * @return
 * @throws Exception
 */
export function formRemoveById (table, primarykey) {
  return request({
    url: apl_mainApi.formRemoveById,
    method: 'post',
    params: {
      table,
      primarykey
    }
  })
}

/**
 * 保存流程表单数据
 * @param formData Map<表名, list<Map<"field: 字段, value: 值", "variable: 变量名">>>
 * @return applyid
 * @throws Exception
 */
export function saveApplyForm (formid, formData) {
  return request({
    url: apl_mainApi.saveApplyForm,
    method: 'post',
    params: {
      formid
    },
    data: formData
  })
}
/**
 * 读取表单数据
 * @param formid
 * @param applyid 业务id
 * @return
 * @throws IOException
 * @throws BusinessException
 */
export function loadApplyForm (formid, applyid) {
  return request({
    url: apl_mainApi.loadApplyForm,
    method: 'post',
    params: {
      formid,
      applyid
    }
  })
}
/**
 * 导入申请公共主表Excel
 */
export function importExcel (data) {
  var body = new FormData()
  body.append('file', data)
  return request({
    url: apl_mainApi.importExcel,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    method: 'post',
    data: body
  })
}

/**
 * 导出申请公共主表Excel模板
 */
export function exportExcelTemplate () {
  return request({
    url: apl_mainApi.exportExcelTemplate,
    method: 'post',
    responseType: 'blob'
  })
}

/**
 * 导出申请接收材料列表
 */
export function output (data) {
  return request({
    url: apl_mainApi.export,
    method: 'post',
    data: data,
    responseType: 'blob'
  })
}
/**
 * 批量删除申请公共主表
 * @param {*} ids
 */
export function delApl_mains (ids) {
  return request({
    url: apl_mainApi.dels,
    method: 'post',
    params: {
      ids
    }
  })
}
/**
 * 删除申请公共主表
 * @param {*} id
 */
export function delApl_main (id) {
  return request({
    url: apl_mainApi.del,
    method: 'post',
    params: {
      id
    }
  })
}
/**
 * 查看、编辑申请公共主表
 * @param {*} id
 */
export function viewApl_main (id) {
  return request({
    url: apl_mainApi.view,
    method: 'get',
    params: {
      id
    }
  })
}
/**
 * 保存申请公共主表
 * @param {*} body
 */
export function saveApl_main (body) {
  return request({
    url: apl_mainApi.save,
    method: 'post',
    data: body
  })
}

/**
 * 查询申请公共主表列表
 * @param {*} body
 */
export function queryApl_mainList (body) {
  return request({
    url: apl_mainApi.list,
    method: 'post',
    data: body
  })
}

/**
 * 提交受理
 * @param {*} body
 */
export function submitAccept (body) {
  return request({
    url: apl_mainApi.submitAccept,
    method: 'post',
    data: body
  })
}

/**
 * 提交不予受理
 * @param {*} body
 * @param params
 */
export function submitRefuse (body, params) {
  return request({
    url: apl_mainApi.submitRefuse,
    method: 'post',
    data: body,
    params: params
  })
}

/**
 * 预审补正材料
 * @param {*} body
 * @returns
 */
export function viewAppend (body) {
  return request({
    url: apl_mainApi.viewAppend,
    method: 'post',
    data: body
  })
}

/**
 * 提交补正
 * @param {*} body
 * @returns
 */
export function submitAppend (body) {
  return request({
    url: apl_mainApi.submitAppend,
    method: 'post',
    data: body
  })
}

/**
 * 提交补正
 * @param {*} body
 * @returns
 */
export function submitBack (body) {
  return request({
    url: apl_mainApi.submitBack,
    method: 'post',
    data: body
  })
}

export function receiveStart (body) {
  return request({
    url: apl_mainApi.receiveStart,
    method: 'post',
    data: body
  })
}

/**
 * 根据流程实例批量查询
 * @returns
 */
export function getByInstids (instid) {
  return request({
    url: apl_mainApi.getByInstids,
    method: 'post',
    params: { 'instid': instid }
  })
}

/**
 * 导出全部的案件表的数据
 * @returns
 */
export function exportAllCase () {
  return request({
    url: apl_mainApi.exportAllCase,
    method: 'post',
    responseType: 'blob'
  })
}


